Imports cmplib01

Public Class ctlCombats
    Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlCombatTurn As System.Windows.Forms.Panel
    Friend WithEvents lblReinforcingUnits As System.Windows.Forms.Label
    Friend WithEvents lblInvolvedUnits As System.Windows.Forms.Label
    Friend WithEvents lblSelectedRules As System.Windows.Forms.Label
    Friend WithEvents pnlCombatsTitle As System.Windows.Forms.Panel
    Friend WithEvents lblCombats As System.Windows.Forms.Label
    Friend WithEvents lstCombats As System.Windows.Forms.ListBox
    Friend WithEvents splCombats As System.Windows.Forms.Splitter
    Friend WithEvents pnlInvolvedChits As System.Windows.Forms.Panel
    Friend WithEvents tvwInvolvedChits As System.Windows.Forms.TreeView
    Friend WithEvents splRulesSplitter As System.Windows.Forms.Splitter
    Friend WithEvents pnlAssignedRules As System.Windows.Forms.Panel
    Friend WithEvents tvwAssignedRules As System.Windows.Forms.TreeView
    Friend WithEvents splReinforcements As System.Windows.Forms.Splitter
    Friend WithEvents pnlReinforcements As System.Windows.Forms.Panel
    Friend WithEvents tvwReinforcements As System.Windows.Forms.TreeView
    Friend WithEvents picSmallBattleMap As System.Windows.Forms.PictureBox
    Friend WithEvents pnlBattlemap As System.Windows.Forms.Panel
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(ctlCombats))
        Me.pnlCombatTurn = New System.Windows.Forms.Panel
        Me.pnlBattlemap = New System.Windows.Forms.Panel
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.picSmallBattleMap = New System.Windows.Forms.PictureBox
        Me.pnlReinforcements = New System.Windows.Forms.Panel
        Me.tvwReinforcements = New System.Windows.Forms.TreeView
        Me.lblReinforcingUnits = New System.Windows.Forms.Label
        Me.splReinforcements = New System.Windows.Forms.Splitter
        Me.pnlAssignedRules = New System.Windows.Forms.Panel
        Me.tvwAssignedRules = New System.Windows.Forms.TreeView
        Me.lblSelectedRules = New System.Windows.Forms.Label
        Me.splRulesSplitter = New System.Windows.Forms.Splitter
        Me.pnlInvolvedChits = New System.Windows.Forms.Panel
        Me.tvwInvolvedChits = New System.Windows.Forms.TreeView
        Me.lblInvolvedUnits = New System.Windows.Forms.Label
        Me.splCombats = New System.Windows.Forms.Splitter
        Me.lstCombats = New System.Windows.Forms.ListBox
        Me.pnlCombatsTitle = New System.Windows.Forms.Panel
        Me.lblCombats = New System.Windows.Forms.Label
        Me.pnlCombatTurn.SuspendLayout()
        Me.pnlBattlemap.SuspendLayout()
        Me.Panel1.SuspendLayout()
        Me.pnlReinforcements.SuspendLayout()
        Me.pnlAssignedRules.SuspendLayout()
        Me.pnlInvolvedChits.SuspendLayout()
        Me.pnlCombatsTitle.SuspendLayout()
        Me.SuspendLayout()
        '
        'pnlCombatTurn
        '
        Me.pnlCombatTurn.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.pnlCombatTurn.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlCombatTurn.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlCombatTurn.Controls.Add(Me.pnlBattlemap)
        Me.pnlCombatTurn.Controls.Add(Me.pnlReinforcements)
        Me.pnlCombatTurn.Controls.Add(Me.splReinforcements)
        Me.pnlCombatTurn.Controls.Add(Me.pnlAssignedRules)
        Me.pnlCombatTurn.Controls.Add(Me.splRulesSplitter)
        Me.pnlCombatTurn.Controls.Add(Me.pnlInvolvedChits)
        Me.pnlCombatTurn.Controls.Add(Me.splCombats)
        Me.pnlCombatTurn.Controls.Add(Me.lstCombats)
        Me.pnlCombatTurn.Controls.Add(Me.pnlCombatsTitle)
        Me.pnlCombatTurn.Location = New System.Drawing.Point(0, 0)
        Me.pnlCombatTurn.Name = "pnlCombatTurn"
        Me.pnlCombatTurn.Size = New System.Drawing.Size(210, 616)
        Me.pnlCombatTurn.TabIndex = 6
        '
        'pnlBattlemap
        '
        Me.pnlBattlemap.Controls.Add(Me.Panel1)
        Me.pnlBattlemap.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.pnlBattlemap.Location = New System.Drawing.Point(0, 518)
        Me.pnlBattlemap.Name = "pnlBattlemap"
        Me.pnlBattlemap.Size = New System.Drawing.Size(208, 96)
        Me.pnlBattlemap.TabIndex = 8
        '
        'Panel1
        '
        Me.Panel1.BackColor = System.Drawing.Color.SteelBlue
        Me.Panel1.Controls.Add(Me.picSmallBattleMap)
        Me.Panel1.Location = New System.Drawing.Point(48, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(112, 96)
        Me.Panel1.TabIndex = 2
        '
        'picSmallBattleMap
        '
        Me.picSmallBattleMap.BackColor = System.Drawing.Color.Black
        Me.picSmallBattleMap.Location = New System.Drawing.Point(8, 0)
        Me.picSmallBattleMap.Name = "picSmallBattleMap"
        Me.picSmallBattleMap.Size = New System.Drawing.Size(96, 96)
        Me.picSmallBattleMap.TabIndex = 1
        Me.picSmallBattleMap.TabStop = False
        '
        'pnlReinforcements
        '
        Me.pnlReinforcements.Controls.Add(Me.tvwReinforcements)
        Me.pnlReinforcements.Controls.Add(Me.lblReinforcingUnits)
        Me.pnlReinforcements.Dock = System.Windows.Forms.DockStyle.Fill
        Me.pnlReinforcements.Location = New System.Drawing.Point(0, 398)
        Me.pnlReinforcements.Name = "pnlReinforcements"
        Me.pnlReinforcements.Size = New System.Drawing.Size(208, 216)
        Me.pnlReinforcements.TabIndex = 7
        '
        'tvwReinforcements
        '
        Me.tvwReinforcements.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.tvwReinforcements.CheckBoxes = True
        Me.tvwReinforcements.Dock = System.Windows.Forms.DockStyle.Fill
        Me.tvwReinforcements.ImageIndex = -1
        Me.tvwReinforcements.Location = New System.Drawing.Point(0, 18)
        Me.tvwReinforcements.Name = "tvwReinforcements"
        Me.tvwReinforcements.SelectedImageIndex = -1
        Me.tvwReinforcements.Size = New System.Drawing.Size(208, 198)
        Me.tvwReinforcements.TabIndex = 28
        '
        'lblReinforcingUnits
        '
        Me.lblReinforcingUnits.Dock = System.Windows.Forms.DockStyle.Top
        Me.lblReinforcingUnits.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblReinforcingUnits.ForeColor = System.Drawing.Color.Black
        Me.lblReinforcingUnits.Location = New System.Drawing.Point(0, 0)
        Me.lblReinforcingUnits.Name = "lblReinforcingUnits"
        Me.lblReinforcingUnits.Size = New System.Drawing.Size(208, 18)
        Me.lblReinforcingUnits.TabIndex = 27
        Me.lblReinforcingUnits.Text = "Reinforcements"
        '
        'splReinforcements
        '
        Me.splReinforcements.BackColor = System.Drawing.Color.SteelBlue
        Me.splReinforcements.Dock = System.Windows.Forms.DockStyle.Top
        Me.splReinforcements.Location = New System.Drawing.Point(0, 392)
        Me.splReinforcements.Name = "splReinforcements"
        Me.splReinforcements.Size = New System.Drawing.Size(208, 6)
        Me.splReinforcements.TabIndex = 6
        Me.splReinforcements.TabStop = False
        '
        'pnlAssignedRules
        '
        Me.pnlAssignedRules.Controls.Add(Me.tvwAssignedRules)
        Me.pnlAssignedRules.Controls.Add(Me.lblSelectedRules)
        Me.pnlAssignedRules.Dock = System.Windows.Forms.DockStyle.Top
        Me.pnlAssignedRules.Location = New System.Drawing.Point(0, 265)
        Me.pnlAssignedRules.Name = "pnlAssignedRules"
        Me.pnlAssignedRules.Size = New System.Drawing.Size(208, 127)
        Me.pnlAssignedRules.TabIndex = 5
        '
        'tvwAssignedRules
        '
        Me.tvwAssignedRules.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.tvwAssignedRules.CheckBoxes = True
        Me.tvwAssignedRules.Dock = System.Windows.Forms.DockStyle.Fill
        Me.tvwAssignedRules.ImageIndex = -1
        Me.tvwAssignedRules.Location = New System.Drawing.Point(0, 21)
        Me.tvwAssignedRules.Name = "tvwAssignedRules"
        Me.tvwAssignedRules.SelectedImageIndex = -1
        Me.tvwAssignedRules.Size = New System.Drawing.Size(208, 106)
        Me.tvwAssignedRules.TabIndex = 25
        '
        'lblSelectedRules
        '
        Me.lblSelectedRules.Dock = System.Windows.Forms.DockStyle.Top
        Me.lblSelectedRules.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblSelectedRules.ForeColor = System.Drawing.Color.Black
        Me.lblSelectedRules.Location = New System.Drawing.Point(0, 0)
        Me.lblSelectedRules.Name = "lblSelectedRules"
        Me.lblSelectedRules.Size = New System.Drawing.Size(208, 21)
        Me.lblSelectedRules.TabIndex = 24
        Me.lblSelectedRules.Text = "Assigned Rules"
        '
        'splRulesSplitter
        '
        Me.splRulesSplitter.BackColor = System.Drawing.Color.SteelBlue
        Me.splRulesSplitter.Dock = System.Windows.Forms.DockStyle.Top
        Me.splRulesSplitter.Location = New System.Drawing.Point(0, 259)
        Me.splRulesSplitter.Name = "splRulesSplitter"
        Me.splRulesSplitter.Size = New System.Drawing.Size(208, 6)
        Me.splRulesSplitter.TabIndex = 4
        Me.splRulesSplitter.TabStop = False
        '
        'pnlInvolvedChits
        '
        Me.pnlInvolvedChits.Controls.Add(Me.tvwInvolvedChits)
        Me.pnlInvolvedChits.Controls.Add(Me.lblInvolvedUnits)
        Me.pnlInvolvedChits.Dock = System.Windows.Forms.DockStyle.Top
        Me.pnlInvolvedChits.Location = New System.Drawing.Point(0, 141)
        Me.pnlInvolvedChits.Name = "pnlInvolvedChits"
        Me.pnlInvolvedChits.Size = New System.Drawing.Size(208, 118)
        Me.pnlInvolvedChits.TabIndex = 3
        '
        'tvwInvolvedChits
        '
        Me.tvwInvolvedChits.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.tvwInvolvedChits.Dock = System.Windows.Forms.DockStyle.Fill
        Me.tvwInvolvedChits.ImageIndex = -1
        Me.tvwInvolvedChits.Location = New System.Drawing.Point(0, 21)
        Me.tvwInvolvedChits.Name = "tvwInvolvedChits"
        Me.tvwInvolvedChits.SelectedImageIndex = -1
        Me.tvwInvolvedChits.Size = New System.Drawing.Size(208, 97)
        Me.tvwInvolvedChits.TabIndex = 27
        '
        'lblInvolvedUnits
        '
        Me.lblInvolvedUnits.Dock = System.Windows.Forms.DockStyle.Top
        Me.lblInvolvedUnits.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblInvolvedUnits.ForeColor = System.Drawing.Color.Black
        Me.lblInvolvedUnits.Location = New System.Drawing.Point(0, 0)
        Me.lblInvolvedUnits.Name = "lblInvolvedUnits"
        Me.lblInvolvedUnits.Size = New System.Drawing.Size(208, 21)
        Me.lblInvolvedUnits.TabIndex = 26
        Me.lblInvolvedUnits.Text = "Involved Chits"
        '
        'splCombats
        '
        Me.splCombats.BackColor = System.Drawing.Color.SteelBlue
        Me.splCombats.Dock = System.Windows.Forms.DockStyle.Top
        Me.splCombats.Location = New System.Drawing.Point(0, 135)
        Me.splCombats.Name = "splCombats"
        Me.splCombats.Size = New System.Drawing.Size(208, 6)
        Me.splCombats.TabIndex = 2
        Me.splCombats.TabStop = False
        '
        'lstCombats
        '
        Me.lstCombats.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.lstCombats.Dock = System.Windows.Forms.DockStyle.Top
        Me.lstCombats.Location = New System.Drawing.Point(0, 44)
        Me.lstCombats.Name = "lstCombats"
        Me.lstCombats.Size = New System.Drawing.Size(208, 91)
        Me.lstCombats.TabIndex = 1
        '
        'pnlCombatsTitle
        '
        Me.pnlCombatsTitle.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlCombatsTitle.Controls.Add(Me.lblCombats)
        Me.pnlCombatsTitle.Dock = System.Windows.Forms.DockStyle.Top
        Me.pnlCombatsTitle.Location = New System.Drawing.Point(0, 0)
        Me.pnlCombatsTitle.Name = "pnlCombatsTitle"
        Me.pnlCombatsTitle.Size = New System.Drawing.Size(208, 44)
        Me.pnlCombatsTitle.TabIndex = 0
        '
        'lblCombats
        '
        Me.lblCombats.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCombats.Location = New System.Drawing.Point(24, 8)
        Me.lblCombats.Name = "lblCombats"
        Me.lblCombats.Size = New System.Drawing.Size(136, 22)
        Me.lblCombats.TabIndex = 0
        Me.lblCombats.Text = "Combats"
        '
        'ctlCombats
        '
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.Controls.Add(Me.pnlCombatTurn)
        Me.Name = "ctlCombats"
        Me.Size = New System.Drawing.Size(210, 616)
        Me.pnlCombatTurn.ResumeLayout(False)
        Me.pnlBattlemap.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.pnlReinforcements.ResumeLayout(False)
        Me.pnlAssignedRules.ResumeLayout(False)
        Me.pnlInvolvedChits.ResumeLayout(False)
        Me.pnlCombatsTitle.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private ptrSelectedBattle As Battle_2
    Private ptrCurrentGame As CampaignerGameData
    Private ptrFMVMap As FMPLib01.FlexMapData
    Private ptrMapBMP As Bitmap
    Private ignoreReduction As Boolean = False

    Private ResPopulating As Boolean = False

    Public Sub ClearData()
        lstCombats.Items.Clear()
        tvwInvolvedChits.Nodes.Clear()
        tvwReinforcements.Nodes.Clear()
        tvwAssignedRules.Nodes.Clear()
        picSmallBattleMap.Image = Nothing

    End Sub


#Region "Combat Panel Actions"
    Private Sub lstCombats_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstCombats.SelectedIndexChanged
        ' list the combat info
        If ptrCurrentGame.selectedPlayer Is Nothing Then Exit Sub

        Try
            ptrSelectedBattle = lstCombats.SelectedItem
            ShowChitsInDirectCombat()
            ' don't forget rules and such :D
            ShowAvailableRules()
            CreateOverviewMap()
            ShowAvailableReinforcementChits()   '// in here we mark who is within Support Range on the smalloverviewmap!

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub ShowChitsInDirectCombat()
        ' shows ALL chits involved in contact combat, not those that are within reinforcement range.
        If (ptrSelectedBattle Is Nothing) Or (ptrCurrentGame.selectedPlayer Is Nothing) Then Exit Sub

        'Dim key As String
        'Dim GndChit As GroundChitType

        tvwInvolvedChits.Nodes.Clear()

        For Each mem As ChitMember In ptrSelectedBattle.InvolvedChits
            Dim nod As New TreeNode
            Dim pvText As String

            If (mem.currentBattlePosture <> BattlePosture_cgd.AttackingSupport Or mem.currentBattlePosture <> BattlePosture_cgd.DefendingSupport) Then
                If mem.UnitType = GroundChitClass_cgd.Battlegroup Then
                    pvText = " [" & DirectCast(mem, BattlegroupChit).CurrentPV & "]"
                Else
                    pvText = ""
                End If
                nod.Text = mem.Name & pvText
                If mem.OwningFaction.Equals(ptrCurrentGame.selectedFaction) Then
                    nod.ForeColor = Color.DarkGreen
                Else
                    nod.ForeColor = Color.DarkRed
                End If
                '// add da ting.
                tvwInvolvedChits.Nodes.Add(nod)

                Select Case mem.UnitType
                    Case GroundChitClass_cgd.Objective
                        nod.ImageIndex = 0
                    Case GroundChitClass_cgd.Battlegroup
                        nod.ImageIndex = 1
                    Case GroundChitClass_cgd.Token, GroundChitClass_cgd.Unit  '// not doing much with these sukkas
                        nod.ImageIndex = 2
                End Select
            End If
        Next

        '' HACK: only considers two opposing factions
        'For Each key In ptrSelectedBattle.InvolvedChits.Keys
        '    Dim nod As New TreeNode
        '    GndChit = ptrSelectedBattle.InvolvedChits.item(key)
        '    ' only list units in direct combat. Those units selected as reinforcing are listed in another box.
        '    If (GndChit.CurrentBattlePosture <> BattlePosture_cgd.AttackingSupport Or GndChit.CurrentBattlePosture <> BattlePosture_cgd.DefendingSupport) Then
        '        nod.Text = GndChit.Name & " [" & GndChit.CurrentPointValue & "]"
        '        If (CampaignerGameData.CDGKEY_FACTION & GndChit.OwningFaction) = ptrCurrentGame.selectedPlayer.FactionKey Then
        '            nod.ForeColor = Color.DarkGreen
        '        Else
        '            nod.ForeColor = Color.DarkRed
        '        End If
        '        tvwInvolvedChits.Nodes.Add(nod)
        '        If GndChit.GroundChitClass = GroundChitClass_cgd.Objective Then
        '            ' add some info about this objective in the objectivetreeview
        '            Dim obj As cmplib01.ObjectiveType
        '            obj = GndChit
        '            ' list properties
        '            nod.ImageIndex = 0
        '        ElseIf GndChit.GroundChitClass = GroundChitClass_cgd.Unit Then
        '            Dim unit As cmplib01.UnitType
        '            unit = GndChit
        '            ' list properties
        '            nod.ImageIndex = 1
        '        ElseIf GndChit.GroundChitClass = GroundChitClass_cgd.Token Then
        '            Dim tok As cmplib01.TokenType
        '            tok = GndChit
        '            ' list properties
        '            nod.ImageIndex = 2
        '        End If
        '    End If
        'Next

    End Sub

    Private Sub ShowAvailableReinforcementChits()
        ' lists for the player chits that are within reinforcement range of this battle (ZOC range)
        ' and their current assignment status (reinforceing, ok, etc) Only units with a status of OK can be assigned as reinforcements.
        ' units that are already reinforcing this battle are marked with a check. 
        ' unchecking a unit marks this unit as no longer supporting the combat, and when the player selects 'Assign', his choices
        ' will be set and any UNCHECKED units will be removed from the battle if they exist, while CHECKED units will be added
        ' if they don't already exist.
        If (ptrSelectedBattle Is Nothing) Or (ptrCurrentGame.selectedPlayer Is Nothing) Then Exit Sub

        'Dim key As String
        'Dim unit As UnitType
        'Dim gc As GroundChitType

        If tvwReinforcements.Nodes.Count > 0 Then tvwReinforcements.Nodes.Clear()

        For Each mem As ChitMember In ptrCurrentGame.Chits
            If mem.UnitType = GroundChitClass_cgd.Battlegroup Then
                Dim batt As BattlegroupChit = mem
                If batt.OwningPlayer.Equals(ptrCurrentGame.selectedPlayer) Then
                    If (batt.Status = GroundUnitStatus_cgd.OK) OrElse (batt.Status = GroundUnitStatus_cgd.Moving) Then
                        If WithinReinforcementRange(batt.Location, ptrSelectedBattle.BattleLocation, batt) = True Then
                            Dim node As New TreeNode(batt.Name)
                            '// reinforcement arrow
                            DrawReinforcementArrow(batt.Location)

                            '// ok, tag is an object, not key.
                            node.Tag = batt
                            tvwReinforcements.Nodes.Add(node)

                        End If
                    ElseIf batt.Status = GroundUnitStatus_cgd.Reinforcing Then
                        If batt.battleInvolvedIn.Equals(ptrSelectedBattle) Then
                            Dim node As New TreeNode(batt.Name)

                            node.Tag = batt
                            node.Checked = True
                            DrawReinforcementArrow(batt.Location, True)
                            tvwReinforcements.Nodes.Add(node)
                        End If
                    End If
                End If
            End If
        Next

    End Sub

    Private Sub DrawReinforcementArrow(ByVal reinforcerlocation As Point, Optional ByVal IsReinforcing As Boolean = False)
        Dim g As Graphics = picSmallBattleMap.CreateGraphics
        Dim smallMapOffset As Single = picSmallBattleMap.Width / 2

        Dim offsetPoint As New Point(reinforcerlocation.X - ptrSelectedBattle.BattleLocation.X + smallMapOffset, reinforcerlocation.Y - ptrSelectedBattle.BattleLocation.Y + smallMapOffset) '// modified as an offset to the location of the battle.

        Dim p As New Pen(Color.Black)
        p.EndCap = Drawing2D.LineCap.ArrowAnchor
        p.StartCap = Drawing2D.LineCap.RoundAnchor

        p.Width = 6
        g.DrawLine(p, offsetPoint.X, offsetPoint.Y, 48, 48)

        If IsReinforcing = True Then
            p.Color = Color.DodgerBlue
        Else
            p.Color = Color.WhiteSmoke
        End If

        p.Width = 4
        g.DrawLine(p, offsetPoint.X, offsetPoint.Y, 48, 48)

        p.Dispose()
        g.Dispose()
    End Sub

    Private Function WithinReinforcementRange(ByVal location As Point, ByVal target As Point, ByVal unit As BattlegroupChit) As Boolean
        'Dim range As Integer = (unit.ptrUnitType.ReinforcementRange / 2) * ptrFMVMap.PixelsPerOneMile

        If XYDistance(location.X, target.X, location.Y, target.Y) <= unit.effectiveReinforcement / 2 Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Sub CreateOverviewMap()

        '// snags a portion of the mapbitmap and displays it for the user
        If ptrMapBMP Is Nothing Then Exit Sub

        '// find the area around the selected battle
        Dim g As Graphics = picSmallBattleMap.CreateGraphics

        g.DrawImage(ptrMapBMP, New RectangleF(0, 0, picSmallBattleMap.Width, picSmallBattleMap.Height), New RectangleF(ptrSelectedBattle.BattleLocation.X - (picSmallBattleMap.Width / 2), ptrSelectedBattle.BattleLocation.Y - (picSmallBattleMap.Height / 2), picSmallBattleMap.Width, picSmallBattleMap.Height), GraphicsUnit.Pixel)

        '// we can draw our options too, like who is in support range and such
        g.Dispose()

    End Sub

#Region "Select and Deselect Reinforcements"

    Private Sub AssignReinforcements()
        Dim nod As TreeNode
        Dim unit As UnitType

        Try
            For Each nod In tvwReinforcements.Nodes
                unit = nod.Tag'ptrCurrentGame.AllChits.Item(nod.Tag)
                If nod.Checked = True Then
                    SelectReinforcement(unit)
                Else
                    DeselectReinforcement(unit)
                End If
            Next
        Catch ex As Exception
            HandleException("ctlCombats.AssignReinforcements", ex)
        End Try
    End Sub

    Private Sub SelectReinforcement(ByRef unit As UnitType)
        ' Ok, if the unit isn't already listed as reinforcing this combat, add it.
        If unit.CurrentBattlePosture = BattlePosture_cgd.NoBattle Then
            If ActivePlayerPOV() = PlayerPOV_cgd.Attacking Then
                unit.CurrentBattlePosture = BattlePosture_cgd.AttackingSupport
                unit.BattleInvolvedInID = ptrSelectedBattle.BattleID
                unit.Status = GroundUnitStatus_cgd.Reinforcing
                ' add to the battle involvedchits
                ptrSelectedBattle.InvolvedChits.add(unit)
                DrawReinforcementArrow(unit.Location, True)
            Else
                unit.CurrentBattlePosture = BattlePosture_cgd.DefendingSupport
                unit.BattleInvolvedInID = ptrSelectedBattle.BattleID
                unit.Status = GroundUnitStatus_cgd.Reinforcing
                ' add to the battles involvedchits
                ptrSelectedBattle.InvolvedChits.add(unit)
                DrawReinforcementArrow(unit.Location, True)
            End If
        End If
    End Sub

    Private Sub DeselectReinforcement(ByRef unit As UnitType)
        ' if the unit is listed as reinforcing, remove it
        If unit.CurrentBattlePosture <> BattlePosture_cgd.NoBattle Then
            unit.CurrentBattlePosture = BattlePosture_cgd.NoBattle
            unit.BattleInvolvedInID = -1
            unit.Status = GroundUnitStatus_cgd.OK
            ptrSelectedBattle.InvolvedChits.Remove(unit.Key)
            DrawReinforcementArrow(unit.Location)
        End If
    End Sub

#End Region


#Region "Select and Deselect Rules"

    Private Sub SelectRule(ByVal chRule As ChitRuleTreeNode)
        ' examines the chitruletreenode and extracts information required

        Dim mem As ChitMember = chRule.Chit

        ResPopulating = True

        Try
            '// if we require resources, check for that.
            If TypeOf chRule.Ru.ptrRule Is ResourceConsumingRuleType Then
                If ResourceConsumption(chRule) = False Then
                    MessageBox.Show("Not enough resources are available to use this rule.", "Insufficient Resources", MessageBoxButtons.OK)
                    chRule.Checked = False
                    ResPopulating = False
                    Exit Sub
                End If
            End If
            DecrementIncrementRuleForUse(mem, chRule.Ru, True)
            '// assign the rule to the battle, it can't be used elsewhere
            AssignRuleToBattle(chRule)
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        ResPopulating = False

    End Sub

    Private Sub DeselectRule(ByVal chRule As ChitRuleTreeNode)
        ' examines the selected assignedRule object in lstAssignedRules and removes the event from
        ' the battle, as well as incrementing the rule available uses if required.
        Try
            DecrementIncrementRuleForUse(chRule.Chit, chRule.Ru, False)
            DeassignRuleToBattle(chRule)
            '// return resources
            If Not ignoreReduction Then
                ReturnResources(chRule)
            Else
                ignoreReduction = False
            End If
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        ' find the rule in the correct chit and set its currentuses to 0
        'Dim gc As GroundChitType
        'Try
        '    Dim mem As ChitMember = chRule.Chit
        '    '   gc = ptrCurrentGame.AllChits.Item(chRule.ChitKey)
        '    ' the last parameter refers to the rule's currentuses... which is how many uses remain for the rule.
        '    DecrementIncrementRuleForUse(mem, chRule.RuleTypeID, chRule.RuleID, False)
        '    DeassignRuleToBattle(chRule)
        '    '// finally, return the resources
        '    If Not ignoreReduction Then
        '        ReturnResources(chRule)
        '    Else
        '        ignoreReduction = False
        '    End If

        'Catch ex As Exception
        '    HandleException(c_Module, ex)
        'End Try

    End Sub

    Private Sub DecrementIncrementRuleForUse(ByRef gc As ChitMember, ByRef ru As Rule, ByVal resetToZero As Boolean)
        ' examine the chit's rule current and max uses and reduce one if required
        'Dim tok As TokenType

        '// rules have been changed to all be "one-shot". If a unit or installation should have multiple of the same rule, add them.
        Try
            For Each testRule As Rule In gc.chitRules
                If testRule.ptrRule.Equals(ru.ptrRule) Then
                    If resetToZero = True Then
                        ru.usesRemaining = 0
                    Else
                        ru.usesRemaining = 1
                    End If
                End If
            Next
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        ' find the rule in this chit's list
        'Dim gcRule As Rule
        'For Each gcRule In gc.chitRules
        '    If gcRule.ruleID = RuleID Then
        '        ' if the rule id's match, reduce the use count
        '        If setCurrentToZero = True Then
        '            gcRule.currentUses = 0
        '            gcRule.battleAssignedTo = ptrSelectedBattle.BattleID
        '        Else
        '            gcRule.currentUses = 1
        '            gcRule.battleAssignedTo = -1
        '        End If
        '        Exit For
        '    End If
        'Next
    End Sub

    Private Sub DeassignRuleToBattle(ByVal chrule As ChitRuleTreeNode)
        'Dim HT As Collection
        'Dim index As Integer

        If ActivePlayerPOV() = PlayerPOV_cgd.Attacking Then
            '    HT = ptrSelectedBattle.AttackerAssigned
            ptrSelectedBattle.AttackerAssignedRules.remove(chrule.Ru)
            chrule.Ru.battleAssignedTo = Nothing
        Else
            '    HT = ptrSelectedBattle.DefenderAssigned
            ptrSelectedBattle.DefenderAssignedRules.remove(chrule.Ru)
            chrule.Ru.battleAssignedTo = Nothing
        End If



        'Try
        '    Dim asgn As AssignedRule
        '    For Each asgn In HT
        '        If CampaignerGameData.CDGKEY_RULE & chrule.RuleID = asgn.RuleKey Then
        '            HT.Remove(index)
        '            'chrule.Checked = False
        '            Exit For
        '        End If
        '        index += 1
        '    Next
        'Catch ex As Exception
        '    HandleException(c_Module, ex)
        'End Try

    End Sub

    Private Sub AssignRuleToBattle(ByVal chrule As ChitRuleTreeNode)
        If ActivePlayerPOV() = PlayerPOV_cgd.Attacking Then
            ptrSelectedBattle.AttackerAssignedRules.add(chrule.Ru)
            chrule.Ru.battleAssignedTo = ptrSelectedBattle
        Else
            ptrSelectedBattle.DefenderAssignedRules.add(chrule.Ru)
            chrule.Ru.battleAssignedTo = ptrSelectedBattle
        End If

    End Sub

    Private Function ResourceConsumption(ByVal chrule As ChitRuleTreeNode) As Boolean
        '// returns false if the resources are not available.

        Dim rest As ResourceConsumingRuleType = chrule.Ru.ptrRule
        Dim cost As ResourceCost

        ' first, check, then, if all is well, decrement the available resources
        For Each cost In rest.Costs
            If ResourceAvailable(cost.ResourceTypeID, cost.ResourceCost) = False Then
                Return False
            End If
        Next

        '// all is well.
        For Each cost In rest.Costs
            ReduceResource(cost.ResourceTypeID, cost.ResourceCost)
        Next

        Return True

    End Function

    Private Function ResourceAvailable(ByVal resID As Integer, ByVal amount As Integer) As Boolean
        Dim totalAmount As Integer
        'Dim resKey As String
        'Dim res As Resource
        'Dim gcKey As String
        'Dim gc As GroundChitType
        'Dim inst As ObjectiveType


        Try
            For Each mem As ChitMember In ptrCurrentGame.Chits
                If mem.OwningFaction.Equals(ptrCurrentGame.selectedFaction) Then
                    If mem.UnitType = GroundChitClass_cgd.Objective Then
                        '// then we need to calculate resources.
                        Dim inst As InstallationChit = DirectCast(mem, InstallationChit)
                        Dim poolItem As ResourcePoolItem
                        For Each poolItem In inst.Resources
                            If poolItem.resourceTypeptr.ResourceTypeID = resID Then
                                totalAmount += poolItem.localAmount


#If DEBUG Then
                                Debug.WriteLine(totalAmount & " available")
#End If

                                If totalAmount >= amount Then Return True
                            End If
                        Next
                    End If
                End If
            Next

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        'For Each gcKey In ptrCurrentGame.AllChits.Keys
        '    gc = ptrCurrentGame.AllChits.Item(gcKey)
        '    If gc.OwningFaction = ptrCurrentGame.selectedFaction.FactionID Then
        '        If gc.GroundChitClass = GroundChitClass_cgd.Objective Then
        '            inst = gc
        '            For Each resKey In inst.ObjectiveResources.HT.Keys
        '                res = inst.ObjectiveResources.Item(resKey)
        '                If res.ResourceTypeID = resID Then
        '                    totalAmount += res.CurrentAmount
        '                    If totalAmount >= amount Then Return True
        '                End If
        '            Next
        '        End If
        '    End If
        'Next

        Return False

    End Function

    Private Sub ReduceResource(ByVal resID As Integer, ByVal amount As Integer)
        Dim totalReduced As Integer
        'Dim resKey As String
        'Dim res As Resource
        'Dim gcKey As String
        'Dim gc As GroundChitType
        'Dim inst As ObjectiveType
        Dim done As Boolean

        Try
            Do Until done
                For Each mem As ChitMember In ptrCurrentGame.Chits
                    If mem.UnitType = GroundChitClass_cgd.Objective Then
                        Dim poolitem As ResourcePoolItem
                        Dim inst As InstallationChit = DirectCast(mem, InstallationChit)
                        For Each poolitem In inst.Resources
                            If poolitem.resourceTypeptr.ResourceTypeID = resID Then
                                If poolitem.localAmount > 0 Then
                                    totalReduced += 1
                                    poolitem.localAmount -= 1
                                End If
                                If totalReduced = amount Then
                                    done = True
                                    Exit Do
                                End If
                            End If
                        Next
                    End If
                Next
            Loop
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        'Do Until done
        '    For Each gcKey In ptrCurrentGame.AllChits.Keys
        '        gc = ptrCurrentGame.AllChits.Item(gcKey)
        '        If gc.GroundChitClass = GroundChitClass_cgd.Objective Then
        '            If gc.OwningFaction = ptrCurrentGame.selectedFaction.FactionID Then
        '                inst = gc
        '                For Each resKey In inst.ObjectiveResources.HT.Keys
        '                    res = inst.ObjectiveResources.Item(resKey)
        '                    If res.ResourceTypeID = resID Then
        '                        If res.CurrentAmount > 0 Then
        '                            totalReduced += 1
        '                            res.CurrentAmount -= 1
        '                        End If
        '                        '// exit when we hit 0
        '                        If totalReduced = amount Then
        '                            done = True
        '                            Exit Do
        '                        End If
        '                    End If
        '                Next
        '            End If
        '        End If
        '    Next
        'Loop

    End Sub

    Private Sub ReturnResources(ByVal chRule As ChitRuleTreeNode)
        Dim ruleT As ResourceConsumingRuleType = chRule.Ru.ptrRule ' ptrCurrentGame.RuleTypes_g.Item(CampaignerGameData.CDGKEY_RULETYPE & chRule.RuleTypeID)
        Dim cost As ResourceCost

        Try
            For Each cost In ruleT.Costs
                IncreaseResource(cost.ResourceTypeID, cost.ResourceCost)
            Next
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub IncreaseResource(ByVal resID As Integer, ByVal amount As Integer)
        '// increases the resource amount if the rule is unassigned.
        Dim totalIncremented As Integer = amount
        'Dim resKey As String
        'Dim res As Resource
        'Dim gcKey As String
        'Dim gc As GroundChitType
        'Dim inst As ObjectiveType
        Dim done As Boolean

        Try
            Do Until done
                For Each mem As ChitMember In ptrCurrentGame.Chits
                    If mem.UnitType = GroundChitClass_cgd.Objective Then
                        Dim inst As InstallationChit = DirectCast(mem, InstallationChit)
                        For Each pitem As ResourcePoolItem In inst.Resources
                            If pitem.resourceTypeptr.ResourceTypeID = resID Then
                                If pitem.localAmount < pitem.maxAmount Then
                                    totalIncremented -= 1
                                    pitem.localAmount += 1
                                    '// exit if done.
                                    If totalIncremented = 0 Then
                                        done = True
                                        Exit Do
                                    End If
                                End If
                            End If
                        Next
                    End If
                Next
            Loop
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        'Do Until done
        '    For Each gcKey In ptrCurrentGame.AllChits.Keys
        '        gc = ptrCurrentGame.AllChits.Item(gcKey)
        '        If gc.GroundChitClass = GroundChitClass_cgd.Objective Then
        '            If gc.OwningFaction = ptrCurrentGame.selectedFaction.FactionID Then
        '                inst = gc
        '                For Each resKey In inst.ObjectiveResources.HT.Keys
        '                    res = inst.ObjectiveResources.Item(resKey)
        '                    If res.ResourceTypeID = resID Then
        '                        If res.CurrentAmount < res.MaxAmount Then
        '                            totalIncremented -= 1
        '                            res.CurrentAmount += 1

        '                            '// exit when we match
        '                            If totalIncremented = 0 Then
        '                                done = True
        '                                Exit Do
        '                            End If
        '                        End If
        '                    End If
        '                Next
        '            End If
        '        End If
        '    Next
        'Loop

    End Sub

#End Region


    Private Sub tvwReinforcements_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwReinforcements.AfterCheck
        AssignReinforcements()
    End Sub

    Private Sub ShowAvailableRules()
        ' this displays the rules available to the player that are in RANGE of the BATTLE (not specific chits)
        'Dim gcKey As String
        'Dim gc As GroundChitType
        'Dim rulet As RuleType
        'Dim rulie As Rule
        Dim ruleOK As Boolean
        'Dim ownerOK As Boolean
        'Dim factKey As String

        Try
            If tvwAssignedRules.Nodes.Count > 0 Then
                tvwAssignedRules.Nodes.Clear()
            End If

            For Each mem As ChitMember In ptrCurrentGame.Chits
                Dim ruleAssignedThisCombat As Boolean = False

                If ownerOk(mem) = True Then
                    ruleOK = False

                    For Each ru As Rule In mem.chitRules
                        If ru.ptrRule.AppliesDuring <> RuleApplies_cgd.NonCombat Then
                            If ru.usesRemaining > 0 Then
                                ruleOK = True
                            Else
                                '// see if it is assigned to this battle.
                                ruleOK = False
                                If ru.battleAssignedTo.Equals(ptrSelectedBattle) Then ruleAssignedThisCombat = True
                            End If

                            '// we'll do the range checking thing and stuff.
                            If ruleOK Then
                                If ru.ptrRule.BasicRange = 0 Then
                                    '// this checks to see if the range is 0, but the rule 'holder' is in combat, if it is, the rule is good.
                                    If ptrSelectedBattle.InvolvedChits.contains(mem) Then
                                        AddAvailableRule(ru.ptrRule, mem, ru)
                                    End If
                                Else
                                    '// range is greater than 0. So, we check range to the combat and determine if its ok 
                                    If XYDistance(mem.Location.X, ptrSelectedBattle.BattleLocation.X, mem.Location.Y, ptrSelectedBattle.BattleLocation.Y) <= ((ru.ptrRule.BasicRange / 2) * ptrFMVMap.PixelsPerOneMile) Then
                                        ' add the rule to the list
                                        AddAvailableRule(ru.ptrRule, mem, ru)
                                    End If
                                End If
                            Else
                                '// if the rule is assigned to the selected battle
                                '// this will allow them to unselect it
                                ' the rule is assigned to SOMETHING, either in this battle or a different battle.
                                ' if the rule is assigned to this battle, AddAvailable with the check already set... otherwise
                                ' add this rule with a checkmark. :P
                                If ruleAssignedThisCombat = True Then
                                    AddAvailableRule(ru.ptrRule, mem, ru, True)
                                End If
                            End If
                        End If
                    Next

                End If

            Next


            'For Each gcKey In ptrCurrentGame.AllChits.Keys
            '    Dim ruleAssignedThisCombat As Boolean = False
            '    'GC = ptrCurrentGame.AllChits.Item(gcKey)
            '    '' check to make sure this player can assign this rule
            '    'ownerOK = False
            '    'If GC.GroundChitClass = GroundChitClass_cgd.Objective Then
            '    '    factKey = ptrCurrentGame.CDGKEY_FACTION & GC.OwningFaction
            '    '    If factKey = ptrCurrentGame.selectedPlayer.FactionKey Then ownerOK = True
            '    'Else
            '    '    If GC.OwningPlayer = ptrCurrentGame.selectedPlayer.PlayerID Then ownerOK = True
            '    'End If
            '    ' check all rules for this chit and see which ones are in range 
            '    If ownerOK Then
            '        For Each rulie In GC.GCRules
            '            ' default ruleOK to false
            '            ruleOK = False
            '            rulet = ptrCurrentGame.RuleTypes_g.Item(CampaignerGameData.CDGKEY_RULETYPE & rulie.ruleTypeID)
            '            If rulet.AppliesDuring <> RuleApplies_cgd.NonCombat Then
            '                ' it applies either during combat, or always, so, check other values

            '                If rulie.currentUses = 1 Then     ' this is how many uses are REMAINING... duh... stupid name.
            '                    ruleOK = True
            '                Else
            '                    ' this rule is assigned somewhere. Is it assigned HERE? In this very battle?
            '                    ruleOK = False
            '                    If rulie.battleAssignedTo = ptrSelectedBattle.BattleID Then
            '                        ruleAssignedThisCombat = True
            '                    End If
            '                End If
            '                ' if the rule is ok for both applies during and available uses, we'll check range

            '                If ruleOK Then
            '                    If rulet.BasicRange = 0 Then
            '                        ' if this guy is involved in the scrap, he'll get to use his rules. Simple.
            '                        If TypeOf GC Is ObjectiveType Then
            '                            If ptrSelectedBattle.InvolvedChits.Contains(CampaignerGameData.CGDKEY_OBJECTIVETYPE & GC.ID) Then
            '                                AddAvailableRule(rulet, gcKey, rulie.ruleID)
            '                            End If
            '                        Else
            '                            If ptrSelectedBattle.InvolvedChits.Contains(gcKey) Then
            '                                AddAvailableRule(rulet, gcKey, rulie.ruleID)
            '                            End If
            '                        End If

            '                    Else
            '                        ' check range
            '                        If XYDistance(GC.Location.X, ptrSelectedBattle.BattleLocation.X, GC.Location.Y, ptrSelectedBattle.BattleLocation.Y) <= (rulet.BasicRange * ptrFMVMap.PixelsPerOneMile) Then
            '                            ' add the rule to the list
            '                            AddAvailableRule(rulet, gcKey, rulie.ruleID)
            '                        End If
            '                    End If

            '                Else ' the rule is NOT ok... meaning its currentuses is set to 1.
            '                    ' the rule is assigned to SOMETHING, either in this battle or a different battle.
            '                    ' if the rule is assigned to this battle, AddAvailable with the check already set... otherwise
            '                    ' add this rule with a checkmark. :P
            '                    If ruleAssignedThisCombat = True Then
            '                        AddAvailableRule(rulet, gcKey, rulie.ruleID, True)
            '                    End If
            '                End If
            '            End If
            '        Next

            '    End If

            'Next

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Function ownerOk(ByVal mem As ChitMember) As Boolean
        If mem.UnitType = GroundChitClass_cgd.Battlegroup Then
            If mem.OwningPlayer.Equals(ptrCurrentGame.selectedPlayer) Then Return True
        Else
            If mem.OwningFaction.Equals(ptrCurrentGame.selectedFaction) Then Return True
        End If

        '// if not, return false
        Return False

    End Function

    Private Sub AddAvailableRule(ByRef ruleT As RuleType, ByVal owningChit As ChitMember, ByVal ru As Rule, Optional ByVal withCheck As Boolean = False)
        'Dim gc As GroundChitType = ptrCurrentGame.AllChits(owningChitKey)
        Dim ruleTypeNode As New ChitRuleTreeNode("[" & owningChit.Name & "] " & ruleT.RuleName, owningChit, ruleT, ru)

        If withCheck = True Then
            ruleTypeNode.Checked = True
        End If

        tvwAssignedRules.Nodes.Add(ruleTypeNode)

    End Sub

    Private Function HasThisRule(ByVal ruleT As RuleType) As Boolean
        Dim asgn As AssignedRule
        'Dim asgnRuleKey As String

        If ActivePlayerPOV() = PlayerPOV_cgd.Attacking Then
            For Each asgn In ptrSelectedBattle.AttackerAssignedRules
                'asgnRule = ptrSelectedBattle.AttackerAssignedRules.Item(asgnRuleKey)
                If asgn.Ru.ptrRule.Equals(ruleT) Then
                    Return True
                End If
            Next
        Else
            For Each asgn In ptrSelectedBattle.DefenderAssignedRules
                If asgn.Ru.ptrRule.Equals(ruleT) Then
                    Return True
                End If
            Next
        End If
        ' if nothing found...
        Return False
    End Function

#End Region


    Private Sub ListCombats()
        If ptrCurrentGame Is Nothing Then Exit Sub

        Try
            Dim bat As Battle_2
            Dim batkey As String
            For Each batkey In ptrCurrentGame.Battles_g.HT.Keys
                bat = ptrCurrentGame.Battles_g.Item(batkey)
                lstCombats.Items.Add(bat)
            Next
        Catch ex As Exception
            HandleException("ctlCombats.ListCombats", ex)
        End Try
    End Sub

    Private Function ActivePlayerPOV() As PlayerPOV_cgd
        If ptrCurrentGame.selectedPlayer.FactionKey = CampaignerGameData.CDGKEY_FACTION & ptrSelectedBattle.AttackingFactionID Then
            Return PlayerPOV_cgd.Attacking
        Else
            Return PlayerPOV_cgd.Defending
        End If
    End Function

    Public Property Game() As CampaignerGameData
        Get
            Return ptrCurrentGame
        End Get
        Set(ByVal Value As CampaignerGameData)
            ptrCurrentGame = Value
            ListCombats()
        End Set
    End Property

    Public Property FMVMap() As FMPLib01.FlexMapData
        Get
            Return ptrFMVMap
        End Get
        Set(ByVal Value As FMPLib01.FlexMapData)
            ptrFMVMap = Value
        End Set
    End Property

    Public Property MapBMP() As Bitmap
        Get
            Return ptrMapBMP
        End Get
        Set(ByVal Value As Bitmap)
            ptrMapBMP = Value
        End Set
    End Property

    Private Sub tvwAssignedRules_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwAssignedRules.AfterCheck
        If ResPopulating = True Then Exit Sub

        If e.Node.Checked = True Then
            SelectRule(CType(e.Node, ChitRuleTreeNode))
        Else
            DeselectRule(CType(e.Node, ChitRuleTreeNode))
        End If
    End Sub

    Private Sub tvwReinforcements_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwReinforcements.AfterSelect
        AssignReinforcements()
    End Sub
End Class
